import request from '../utils/request'

/**
 * 获取角色列表
 *
 * @returns
 */
export const getRoles = () => {
  return request({
    url: '/roles',
    method: 'get'
  })
}

/**
 * 添加角色
 *
 * @returns
 */
export const postRoles = params => {
  return request({
    url: '/roles',
    method: 'post',
    data: params
  })
}

/**
 * 根据 id 查询角色信息
 *
 * @param {*} params
 * @returns
 */
export const getRolesInfoById = params => {
  return request({
    url: `/roles/${params}`,
    method: 'get'
  })
}

/**
 * 编辑角色信息
 *
 * @param {*} params
 * @returns
 */
export const putEditRolesInfo = params => {
  return request({
    url: `/roles/${params.roleId}`,
    method: 'put',
    data: {
      roleName: params.roleName,
      roleDesc: params.roleDesc
    }
  })
}

/**
 * 删除角色
 *
 * @param {*} params
 * @returns
 */
export const deleteRolesById = params => {
  return request({
    url: `/roles/${params}`,
    method: 'delete'
  })
}

/**
 * 分配用户角色
 *
 * @param {*} params
 * @returns
 */
export const putUsersRole = params => {
  return request({
    url: `/users/${params.id}/role`,
    method: 'put',
    data: {
      rid: params.rid
    }
  })
}

/**
 * 获取所有权限列表
 *
 * @param {type: tree / list} params
 * @returns
 */
export const getAllRights = params => {
  return request({
    url: `/rights/${params.type}`,
    method: 'get'
  })
}

/**
 * 分配角色权限
 *
 * @param {*} params
 * @returns
 */
export const postRolesRights = params => {
  return request({
    url: `/roles/${params.roleId}/rights`,
    method: 'post',
    data: params
  })
}

/**
 * 删除角色指定权限
 *
 * @param {*} params
 * @returns
 */
export const delRolesRights = params => {
  return request({
    url: `/roles/${params.roleId}/rights/${params.rightId}`,
    method: 'delete'
  })
}
